const { customersModel } = require('./models/customersModels');

//获取所有客户
module.exports.getCustomers = async (params) => {
    const customers = await customersModel.find({del:false}).populate('salesman');
    // const customers = await customersModel.find({del:false});
    return customers;
}

//通过id获取客户
module.exports.getCustomerById = async (params) => {
    const customers = await customersModel.find({_id:params}).populate('salesman');
    return customers;
}

//新增客户
module.exports.addCustomer = async (params) => {
    const result = await customersModel.create(params);
    return result;
}

//修改客户信息
module.exports.updateCustomerById = async (params) => {
    const result = await customersModel.updateOne({_id:params._id},params);
    return result;
}

//删除客户
module.exports.delCustomerById = async (params) =>{
    const result = await customersModel.updateOne({"_id":params},{"del":true});
    return result;
}